<template>
  <div class="recruit">
    <h2 class="mytitle">学生会管理/学生会招人</h2>
    <div class="mycontent">
      <div class="recruit-content">
        <h3>开启招人</h3>
        <el-table :data="tableData1" border style="width: 100%">
          <el-table-column fixed prop="depName" label="部门名称" width="120">
          </el-table-column>
          <el-table-column fixed prop="depDesc" label="部门描述">
          </el-table-column>
          <el-table-column fixed="right" label="操作" width="100">
            <template slot-scope="scope">
              <el-button @click="zhaoren(scope.row)" type="text" size="small"
                >开启招人</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>

      <div class="recruit-content">
        <h3>关闭招人</h3>
        <el-table :data="tableData2" border style="width: 100%">
          <el-table-column fixed prop="depName" label="部门名称" width="120">
          </el-table-column>
          <el-table-column fixed prop="depDesc" label="部门描述">
          </el-table-column>
          <el-table-column fixed="right" label="操作" width="100">
            <template slot-scope="scope">
              <el-button @click="guanbi(scope.row)" type="text" size="small"
                >关闭招人</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script>
import Api from "../assets/js/api";
export default {
  data() {
    return {
      tableData1: [],
      tableData2: [],
    };
  },
  methods: {
    depfindall1() {
      // 查询所有部门接口
      this.$http({
        url: Api.depfindby, //接口
        method: "POST", //请求方式 默认get
        headers: {
          JWTHeaderName: sessionStorage.getItem("token"),
        },
        data: {
          depStatus: 1,
        }, // data数据
      }).then((res) => {
        if (res.data.status == 0) {
          // console.log(1);
          
          // console.log(res.data.data);
          this.tableData1 = res.data.data;
        }
      });
    },
    depfindall2() {
      // 查询所有部门接口
      this.$http({
        url: Api.depfindby, //接口
        method: "POST", //请求方式 默认get
        headers: {
          JWTHeaderName: sessionStorage.getItem("token"),
        },
        data: {
          depStatus: 0,
        }, // data数据
      }).then((res) => {
        if (res.data.status == 0) {
          console.log(2);
          console.log(res.data.data);
          this.tableData2 = res.data.data;
        }
      });
    },
    // 开始招人按钮
    zhaoren(row) {
      console.log(row);
      this.$http({
        url: Api.depupdate, //接口
        method: "POST", //请求方式 默认get
        headers: {
          JWTHeaderName: sessionStorage.getItem("token"),
        },
        data: {
          depStatus: 0,
          depId: row.depId,
        }, // data数据
      }).then((res) => {
        this.depfindall1();
        this.depfindall2();
      });
    },
    // 关闭招人按钮
    guanbi(row) {
      this.$http({
        url: Api.depupdate, //接口
        method: "POST", //请求方式 默认get
        headers: {
          JWTHeaderName: sessionStorage.getItem("token"),
        },
        data: {
          depStatus: 1,
          depId: row.depId,
        }, // data数据
      }).then((res) => {
        this.depfindall1();
        this.depfindall2();
      });
    },
  },
  mounted() {
    this.depfindall1();
    this.depfindall2();
  },
};
</script>

<style scoped>
.mytitle {
  margin-top: 0;
}
.recruit-content {
  margin-top: 20px;
}
</style>
